import logging
from rest_framework.views import APIView
from rest_framework.response import Response
import rest_framework_simplejwt
import rest_framework_simplejwt.authentication

from utils.auth import TokenAuthentication
from utils.permission import AdministratorRole

# Create your views here.


class LoginView(APIView):
    authentication_classes = []
    permission_classes = []

    def get(self, request):
        return Response({"status": 0, "message": "Login View"})


class UserView(APIView):
    """这个视图用来测试`authentication_classes`： `TokenAuthentication`

    Args:
        APIView (_type_): _description_

    Returns:
        _type_: _description_
    """

    authentication_classes = [TokenAuthentication]
    permission_classes = [AdministratorRole]

    def get(self, request, username: str):
        # self.dispatch()
        logging.info("executing the UserView > get")
        request.user = username
        logging.debug(f"request.user: {request.user} \t request.auth: {request.auth}")
        return Response({"status": 0, "message": "User View"})


class OrderView(APIView):
    def get(self, request):
        return Response({"status": 0, "message": "Order View"})


class ProfileView(APIView):
    authentication_classes = [rest_framework_simplejwt.authentication.JWTAuthentication]

    def get(self, request):
        return Response({"status": 0, "message": "Profile View"})
